﻿using System;
using Serilog;
using Topshelf;

namespace Elasticsearch.Synchronize.Monitor
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            HostFactory.Run(x =>
            {
                Log.Logger = new LoggerConfiguration()
                    .MinimumLevel.Debug()
                    .WriteTo.ColoredConsole()
                    .CreateLogger();
                x.UseSerilog();

                x.UseAssemblyInfoForServiceInfo();

                x.Service(settings => new JobService(), s =>
                {
                    s.BeforeStartingService(_ => Log.Logger.Debug("BeforeStart"));
                    s.BeforeStoppingService(_ => Log.Logger.Debug("BeforeStop"));
                });

                x.SetStartTimeout(TimeSpan.FromSeconds(10));
                x.SetStopTimeout(TimeSpan.FromSeconds(10));

                x.OnException((exception) => { Log.Logger.Error("Exception thrown - " + exception.Message); });
            });
        }
    }
}